package com.example.demo.study.lambda;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

//结论:对100万个字符串进行排序和计数操作，串行和并行运算的用时差别还是很明显的
public class LambdaTest12 {

    public static void main(String[] args) {

        //生成100万个不同的字符串放到集合中
        int max = 1000000;
        List<String> values = new ArrayList<String>(max);
        for (int i = 0; i < max; i++) {
            UUID uuid = UUID.randomUUID();
            values.add(uuid.toString());
        }


        //1纳秒*10^9=1秒
        long t0 = System.nanoTime();
        //串行stream
        //long count = values.stream().sorted().count();
        //并行stream
        long count = values.parallelStream().sorted().count();
        long t1 = System.nanoTime();

        long time = t1 - t0;
        System.out.println(count);
        System.out.println(time);
    }

}

